local CommonOHOH = _G.CommonOHOH;
local M = CommonOHOH.class.new(script, CommonOHOH.files.BaseComponent(),script.Parent.Name.."_"..script.Name);

local TrianObjClass=require(script.Parent.TrianObj) 
function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)
	M.super.ctor(self, parent);

     self.player=self.parent

	self.TrianList={}

	for _,v in pairs(CommonOHOH:GetPath_Loop("Train",game.Workspace):GetChildren()) do
		self:CreateTrianObjs(v)
	end

end;

function M.CreateTrianObjs(self,folder)
	local trianId=tonumber(folder.Name)
	for k,v in pairs(folder:GetChildren()) do
		local trianClass=TrianObjClass.new(trianId,v,self.parent,self)
        self.TrianList[trianClass:GetGuid()]=trianClass
	end
end

function M.FindTrianObj(self,guid)
     return  self.TrianList[guid]
end


-- 获取训练数值
function M.GetTrianValue(self)

     local baseList= self.player.TrainValueBaseEvent:Action()
     local mulList= self.player.TrainValueMulEvent:Action()
     local mulList2= self.player.TrainValueMul2Event:Action()

     local addList= self.player.TrainValueAddEvent:Action()
  
     local base=0
     for _,v in pairs(baseList) do
          base=base+v
     end
  
     local mul=1
  
     for _,v in pairs(mulList) do
          mul=mul+v
     end


     local mul2=1
  
     for _,v in pairs(mulList2) do
          mul2=mul2*v
     end
  

  
     local add=0
  
     for _,v in pairs(addList) do
           add=add+v
      end
  
     --  print("-------GetTrianValue-----------",base,mul,mul2,add)
      return base*mul*mul2+add
  end
 
 
  -- 获取加的经验值
 function M.GetExpValue(self,base)
     base=base or 0
     local baseList= self.player.ExpValueBaseEvent:Action()
     local mulList= self.player.ExpValueMulEvent:Action()
     local addList= self.player.ExpValueAddEvent:Action()

     local mul2List= self.player.ExpValueMul2Event:Action()

     for _,v in pairs(baseList) do
          base=base+v
     end
  
     local mul=1
  
     for _,v in pairs(mulList) do
          mul=mul+v
     end
  
     local add=0
  
     for _,v in pairs(addList) do
           add=add+v
      end
  
      local mul2=1
      for _,v in pairs(mul2List) do
          mul2=mul2*v
     end


      return base*mul*mul2+add
  end


 --获取训练Cd
 function M.GetTrianCd(self,weapon)
      local baseList= self.player.TrainCdBaseEvent:Action(weapon)
     local mulList= self.player.TrainCdMulEvent:Action(weapon)
     local addList= self.player.TrainCdAddEvent:Action(weapon)
  
     local base=0
     for _,v in pairs(baseList) do
          base=base+v
     end
  
     local mul=1
  
     for _,v in pairs(mulList) do
          mul=mul+v
     end
  
     local add=0
  
     for _,v in pairs(addList) do
           add=add+v
      end
  
      return base*(1/mul)+add
 end
 

 --开启攻击CD检测
function M.OpenAttackCdCheck(self)

     if self.GetAttackCDEventCon then
          return 
     end
     --检测攻击CD
     self.GetAttackCDEventCon=  self.player.GetAttackCDEvent:Connect(function(weapon,tp)
         return self:GetTrianCd(weapon)
     end)
 
 end
 
 --关闭攻击CD检测
 function M.CloseAttackCdCheck(self)
     if self.GetAttackCDEventCon then
         self.GetAttackCDEventCon:Disconnect()
         self.GetAttackCDEventCon=nil
     end
 end

 

function M.dtor(self)
	M.super.dtor(self);
end

return M